package com.bite.book.config;

import com.bite.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
//@ResponseBody
//@ControllerAdvice
@RestControllerAdvice
public class ErrorAdvice {
    @ExceptionHandler
    public Result handler1(Exception e) {
        log.error("发生异常，e:",e);
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler
    public Result handler2(NullPointerException e) {
        log.error("发生NullPointerException异常，e:",e);
        return Result.fail("发生空指针异常:"+e.getMessage());
    }
    @ExceptionHandler
    public Result handler3(ArithmeticException e) {
        log.error("发生ArithmeticException异常，e:",e);
        return Result.fail("发生算术异常:"+e.getMessage());
    }
}
